<template>
<div class="container">
  <el-form ref="form" :model="form" label-width="80px">
    <el-form-item label="仓库名称">
      <el-input v-model="form.warehouseName"></el-input>
    </el-form-item>

    <el-form-item label="仓库备注">
      <el-input v-model="form.remark"></el-input>
    </el-form-item>

    <el-form-item label="是否启用">
      <el-switch v-model="form.status"></el-switch>
    </el-form-item>

    <el-form-item>
      <el-button type="primary" @click="onSubmit">确认修改</el-button>
      <el-button @click="canceUpdateWarehouse">取消</el-button>
    </el-form-item>
  </el-form>
</div>
</template>

<script>
import axios from "axios";

export default {
  name: "updatewarehouse",
  data(){
    return{
      form:{
        id:'',
        warehouseName:'',
        status:false,
        remark:'',
      }
    }
  },
  mounted() {
    this.$bus.$on("warehouse/updatewarehouse",(obj)=>{
      console.info('传递过来的obj',obj)
      let status = obj.status;
      this.form.id=obj.id;
      this.form.warehouseName=obj.warehouseName;
      this.form.remark=obj.remark;
      if (status==0||status=='0'){
        this.form.status=true
      }
      else this.form.status=false
    })
    console.info('组装完成的数据',this.form)
  },
  methods:{
    canceUpdateWarehouse(){
      this.$bus.$emit('warehouse/closeUpdateWarehouse',false)
    },
    onSubmit(){
      this.form.status=this.form.status?0:1;
      axios({
        url:"http://localhost:8080/api/warehouse/update",
        method:'put',
        data:this.form
      }).then((resp)=>{
        if (resp.data.code==200){

          this.$message({
            message:resp.data.msg,
            type:'success'
          })
        }
        else this.$message({
          message:resp.data.msg,
          type:'error'
        })
        //关闭对话框
        this.$bus.$emit('warehouse/closeUpdateWarehouse',true)
      })
    }
  }
}
</script>

<style scoped>

</style>